package com.uex.dev.manage.admin.controller;

import com.uex.dev.manage.admin.po.MaintainPO;
import com.uex.dev.manage.admin.po.ProblemPO;
import com.uex.dev.manage.admin.service.IProblemService;
import com.uex.dev.manage.admin.vo.problem.ProblemMaintainInfo;
import com.uex.dev.manage.admin.vo.problem.ProblemInfoResp;
import com.uex.dev.manage.common.base.ModelResult;
import com.uex.dev.manage.common.base.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author lzs
 * @create 2024/03/01
 * @description
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@Tag(name = "维护信息")
@RequestMapping("/problem")
@RestController
public class ProblemController {

    @Resource
    private IProblemService problemService;

    @Operation(description = "查看问题列表")
    @GetMapping("/list")
    public ModelResult<PageResult<ProblemInfoResp>> list(Integer deviceId, @RequestParam Integer page, @RequestParam Integer record) {
        return new ModelResult<>(problemService.selectList(deviceId, page, record));
    }

    @Operation(description = "查看问题详情")
    @GetMapping("/detail")
    public ModelResult<ProblemInfoResp> getDetail(@RequestParam Integer problemId) {
        return new ModelResult(problemService.getDetail(problemId));
    }

    @Operation(description = "查看问题维修记录及详情")
    @GetMapping("/maintain")
    public ModelResult<PageResult<ProblemMaintainInfo>> getMaintain(Integer problemId, @RequestParam Integer page, @RequestParam Integer record) {
        return new ModelResult<>(problemService.getMaintain(problemId, page, record));
    }

    @Operation(description = "添加或更新问题记录")
    @PostMapping("/update")
    public ModelResult updateProblem(@RequestBody ProblemPO problemDetailInfo) {
        problemService.updateProblem(problemDetailInfo);
        return ModelResult.SUCCESS_RESULT;
    }

    @Operation(description = "添加或更新维修记录")
    @PostMapping("/maintain")
    public ModelResult updateMaintain(@RequestBody MaintainPO maintainUpdateReq) {
        problemService.updateMaintain(maintainUpdateReq);
        return ModelResult.SUCCESS_RESULT;
    }
}

